package com.manage.platform.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.manage.platform.context.UserContext;
import com.manage.platform.dto.NewCenterDto;
import com.manage.platform.dto.query.NewCenterQuery;
import com.manage.platform.entity.NewCenterEntity;
import com.manage.platform.mapper.NewCenterMapper;
import com.manage.platform.utils.RPage;
import com.manage.platform.vo.NewCenterVo;
import com.manage.platform.vo.UserVo;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * YWD
 * 2025/9/28
 */
@AllArgsConstructor
@Service
public class NewCenterServiceImpl extends ServiceImpl<NewCenterMapper, NewCenterEntity> {


    public RPage<List<NewCenterVo>> getNewCenterPage(NewCenterQuery query) {
        Page<Object> page = PageHelper.startPage(query.getPage(), query.getLimit());
        List<NewCenterVo> list = this.baseMapper.getNewCenterPage(query);
        return RPage.ok(list, query.getPage(), query.getLimit(), page.getTotal());
    }

    public NewCenterVo getNewCenterDetails(Long id) {
        return BeanUtil.copyProperties(this.getById(id), NewCenterVo.class);
    }

    public Boolean saveNewCenter(NewCenterDto dto) {
        UserVo userVo = UserContext.getUser();
        dto.setUserId(userVo.getId());
        return save(BeanUtil.copyProperties(dto, NewCenterEntity.class));
    }

    public Boolean updateNewCenter(NewCenterDto dto) {
        return updateById(BeanUtil.copyProperties(dto, NewCenterEntity.class));
    }

    public Boolean deleteNewCenter(Long id) {
        return removeById(id);
    }

    public Boolean deleteBatchNewCenter(List<Long> ids) {
        return removeBatchByIds(ids);
    }

    public List<NewCenterVo> getNewTopList(String type,Integer category) {
          return this.baseMapper.getNewTopList(type,category);
    }

}
